var publishAppInfo = {
	id:-1,	
	account:'',
	load : function () {
		Ext.QuickTips.init();
		this.eventRegister();
		var qs =  new QueryString();
		publishAppInfo.account = qs.get("account");

	         $.ajax({
	             url: '/ad/sys/com/control/AdCategorService.php',
	             cache: false,
	             dataType: 'json',
	                 type:'get',
	             data: { action: 'getAll'
		             },
	             error: function(xhr) {
	               alert('Ajax request 發生錯誤');
	             },
	             success: function(response) {
	                       var arrays=(response);
	                       var html='';
	                       $(arrays).each(function(index){
		                       if(index%5==0&&index!=0)
			                       html+="<br/>";
		                       html+='  <input name="adcategorId" type="radio" value="'+this.Value+'" />'+this.Text+'&nbsp;';
		                       });
	                       $('#adCategorSpan').html(html);
	              
	             }
	         });
	
	 
	},
	 
	eventRegister : function () {
		Ext.get("confirm").on('click',this.confrim);  //確認,新增使用者		
	},
	
	
	
	confrim : function () {	   	 
	    
	    waitShow("修改中...");
	    Ext.Ajax.request({
	    	method : "POST",
	     	form : "appInfoForm",
	     	params: {id:publishAppInfo.id},
	    	callback : function (options, se, rsp) {
	    		waitHide();
	    		var obj = rsp.responseText.toJSON();  
	    		if (obj.result =="1") {
	    			alert("修改成功!");
	    			var path='publishMAppList.php';
	    			if(publishAppInfo.account!=null && publishAppInfo.account.length>0)
	    				path=path+'?account='+publishAppInfo.account;
	    			window.location.href=path;
	    		} else{
	    			alert(obj.msg);
	    		}
	    	}
	    	
	    });
 	}  
};
Ext.onReady(function (){
	publishAppInfo.load();
});
$(document).ready(function(){
    $.ajax({
        url: '/ad/sys/com/control/AdCategorService.php',
        cache: false,
        dataType: 'json',
            type:'get',
        data: { action: 'getAll'
            },
        error: function(xhr) {
          alert('Ajax request 發生錯誤');
        },
        success: function(response) {
                  var arrays=(response);
                  var html='';
                  $(arrays).each(function(index){
                      if(index%5==0&&index!=0)
	                       html+="<br/>";
                      html+='  <input name="adcategorId" type="radio" value="'+this.Value+'" />'+this.Text+'&nbsp;';
                      });
                  $('#adCategorSpan').html(html);
                  init();
         
        }
    });
    function init()
    {
		var qs =  new QueryString();
		publishAppInfo.id = qs.get("id");

    $.ajax({
            url: '/ad/sys/com/control/publish/AppInfoService.php',
            cache: false,
            dataType: 'JSON',
                type:'get',
            data: { action: 'getAppInfo',id:publishAppInfo.id
	             },
            error: function(xhr) {
              alert('Ajax request 發生錯誤');
            },
            success: function(response) {
                var appInfo=(response[0]);
                $("select[name='testAction']").val(appInfo.testAction);
                $("select[name='status']").val(appInfo.status);
                $("input[name='name']").val(appInfo.name);
                $("input[name='md5Key']").val(appInfo.md5key);
                                              $("textarea[name='description']").val(appInfo.description);
                $("input:[name=adcategorId]:radio").each(function(){
    	            if (this.value == appInfo.adcategorId ){
    	                this.checked=true;
    	            }
    	        });
                $("input:[name=appType]:radio").each(function(){
    	            if (this.value == appInfo.appType ){
    	                this.checked=true;
    	            }
    	        });
             }
        });
    }
	
});


